<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>地图</title>
    <style>
    	body{
    		margin: 0;
    	}
    .anchorBL{display:none} 
    </style>
</head>
<body>
	<header id="statusBar">
        <div style="height:75px;background: #298cb4;display: table;width: 100%;">
           <div style="height:50px;margin-top: 25px;line-height: 50px;color: #ffffff;background: #1e6887;">
               <div style="z-index: 999;margin-left: 10px;position: fixed;" onclick="closeMap();">
	           返回
	           </div>
	           <div style="text-align: center;font-weight:bold;width: 100%;">
	           酒店预订
	           </div>
           </div>
        </div>
	</header>
	<div id="map">
	</div>
      <div onclick="showRoute()" style="line-height:40px;position:absolute;bottom:0;font-size:large;width: 100%;height: 40px;background-color: #005DA9;color: #F9F6F6;text-align: center;">显示线路</div>
</body>
<script src="../../template/js/jquery.js"></script>
<script type="text/javascript" src="../../script/constants.js"></script>
<script type="text/javascript" charset="UTF-8" src="../../script/naes.js"></script>
<script src="../../script/api.js"></script>
<script type="text/javascript">
    var l;
	var t;
	apiready = function(){
		var address = api.pageParam.name;
		var map = api.require('bMap');
//		    map.setRect({
//			    rect: {
//			        x: os.l,
//			        y: os.t,
//			        w: api.winWidth,
//			        h: api.winHeight-75
//			    }
//			});
			map.getCoordsFromName({
			    address: address
			}, function(res, err) {
			var os = $api.offset($api.dom('#map'));
			    if (res.status) {
			        l = res.lon;
			        t = res.lat;
			        map.open({
					    rect: {
					        x: os.l,
					        y: os.t,
					        w: api.winWidth,
					        h: api.winHeight-115
					    },
					    center: {
					        lon: res.lon,
					        lat: res.lat
					    },
					    zoomLevel: 15,
					    showUserLocation: true,
					    fixed: false
					}, function(r) {
					    if (r.status) {
					        //alert('地图打开成功');
					        map.addAnnotations({
							    annotations: [{
							        id: 1,
							        lon: res.lon,
					                lat: res.lat
							    }],
							    icon: '',
							    draggable: false
							}, function(tt) {
							    if (tt) {
							        //alert(ret.id);
							    }
							});
					    }
					});
			    }
			});
	};
	
	function showRoute(){
	var map = api.require('bMap');
		map.getLocation({
	    accuracy: '100m',
	    autoStop: true,
	    filter: 1
	}, function(ret, err) {
	    if (ret.status) {
	        map.searchRoute({
			    id: 1,
			    type: 'drive',
			    policy: 'ecar_fee_first',
			    start: {
			        lon: ret.lon,
			        lat: ret.lat
			    },
			    end: {
			        lon: l,
			        lat: t
			    }
			}, function(ret, err) {
			    if (ret.status) {
			        //api.alert({ msg: JSON.stringify(ret) });
			        map.drawRoute({
			            id: 1,
			            autoresizing: false,
			            index: 0,
			            styles: {
			                start: {
			                    icon: 'widget://image/bmap_start.png'
			                },
			                end: {
			                    icon: 'widget://image/bmap_end.png'
			                }
			            }
			        }, function(ret) {
			            console.log({ msg: JSON.stringify(ret) });
			        });
			    }
			});
	    } else {
	        alert(err.code);
	    }
	});
	}
	
	function closeMap(){
	    api.sendEvent({
	        name:'closeMappage'
        });
		api.closeWin();
	}
</script>
</html>